﻿using System;
using System.Windows;
using System.Windows.Input;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        ///         UpdateSubjectWindow.xaml 的交互逻辑
        /// </summary>
        public partial class UpdateSubjectWindow
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public UpdateSubjectWindow()
                {
                        InitializeComponent();
                }

                private void Window_Loaded(object sender, RoutedEventArgs e)
                {
                        LayoutRoot.DataContext = _gm;
                }


                private void Window_OnMouseDown(object sender, MouseButtonEventArgs e)
                {
                        if (e.ChangedButton == MouseButton.Left)
                        {
                                DragMove();
                        }
                }

                private void AcceptButton_Click(object sender, RoutedEventArgs e)
                {
                        if (String.IsNullOrEmpty(_gm.Subject.Name))
                        {
                                MessageBox.Show("科目名称不能为空");
                                return;
                        }

                        if (String.IsNullOrEmpty(_gm.Subject.Code))
                        {
                                MessageBox.Show("科目代码不能为空");
                                return;
                        }

                        try
                        {
                                _gm.Subject.Update();
                        }
                        catch (Exception ex)
                        {
                                MessageBox.Show(ex.Message);
                                return;
                        }

                        finally
                        {
                        }

                        Close();
                }
        }
}